//
// Created by 17775 on 2024/10/12.
//

#include "Single_Header.h"


Single_Header::Single_Header(int & docId) : _iSingleDocId(docId) {

}

// General
QString Single_Header::getTitle() {
    char szTitle_buffer[50];
    int nSize = _countof(szTitle_buffer);
    RayCi_Single_Header_General_getTitleA(_iSingleDocId, szTitle_buffer, &nSize);
    return {szTitle_buffer};
}

int Single_Header::getSizeX() {
    int sizeX = 0;
    RayCi_Single_Header_General_getSizeX(_iSingleDocId, &sizeX);
    return sizeX;
}

int Single_Header::getSizeY() {
    int sizeY = 0;
    RayCi_Single_Header_General_getSizeX(_iSingleDocId, &sizeY);
    return sizeY;
}

int Single_Header::getFrameCount() {
    int frameCount = 0;
    RayCi_Single_Header_General_getSizeX(_iSingleDocId, &frameCount);
    return frameCount;
}

QString Single_Header::getUser() {
    char szUser_buffer[50];
    int nSize = _countof(szUser_buffer);
    RayCi_Single_Header_General_getUserA(_iSingleDocId, szUser_buffer, &nSize);
    return {szUser_buffer};
}

QString Single_Header::getComment() {
    char szComment_buffer[100];
    int nSize = _countof(szComment_buffer);
    RayCi_Single_Header_General_getUserA(_iSingleDocId, szComment_buffer, &nSize);
    return {szComment_buffer};
}

// RayCi
QString Single_Header::getName() {
    char szName_buffer[50];
    int nSize = _countof(szName_buffer);
    RayCi_Single_Header_Camera_getNameA(_iSingleDocId, szName_buffer, &nSize);
    return {szName_buffer};
}

QString Single_Header::getSerial() {
    char szSerial_buffer[50];
    int nSize = _countof(szSerial_buffer);
    RayCi_Single_Header_Camera_getSerialA(_iSingleDocId, szSerial_buffer, &nSize);
    return {szSerial_buffer};
}

QString Single_Header::getSetting() {
    char szSetting_buffer[100];
    int nSize = _countof(szSetting_buffer);
    RayCi_Single_Header_Camera_Settings_getA(_iSingleDocId, szSetting_buffer, &nSize);
    return {szSetting_buffer};
}

double Single_Header::getExposureTime() {
    double dExposureTime = 0;
    RayCi_Single_Header_Camera_getExposureTime(_iSingleDocId, &dExposureTime);
    return dExposureTime;
}

double Single_Header::getGain() {
    double dGain = 0;
    RayCi_Single_Header_Camera_getGain(_iSingleDocId, &dGain);
    return dGain;
}

double Single_Header::getOffset() {
    double dOffset = 0;
    RayCi_Single_Header_Camera_getOffset(_iSingleDocId, &dOffset);
    return dOffset;
}

double Single_Header::getTemperature() {
    double dTemperature = 0;
    RayCi_Single_Header_Camera_getTemperature(_iSingleDocId, &dTemperature);
    return dTemperature;
}

void Single_Header::setSpatialManually(const bool bSpatialManually, const double dSizeX, const double dSizeY) const {
    RayCi_Single_Settings_Units_Power_setManually(_iSingleDocId, bSpatialManually);
    if (bSpatialManually) {
        RayCi_Single_Settings_Units_Spatial_setPixelSize(_iSingleDocId, dSizeX, dSizeY);
    }
}

double Single_Header::getPixelSizeX() {
    double dPixelSizeX = 0;
    RayCi_Single_Settings_Units_Spatial_getPixelSizeX(_iSingleDocId, &dPixelSizeX);
    return dPixelSizeX;
}

double Single_Header::getPixelSizeY() {
    double dPixelSizeX = 0;
    RayCi_Single_Settings_Units_Spatial_getPixelSizeY(_iSingleDocId, &dPixelSizeX);
    return dPixelSizeX;
}

QString Single_Header::getSpatialUnit() {
    char szSpatialUnit_buffer[10];
    int nSize = _countof(szSpatialUnit_buffer);
    RayCi_Single_Header_Camera_Settings_getA(_iSingleDocId, szSpatialUnit_buffer, &nSize);
    return {szSpatialUnit_buffer};
}

bool Single_Header::setSpatialUnit(const QString &unit) const {
    const auto byteArray = unit.toUtf8();
    const auto spUnit = byteArray.constData();
    auto ok = RayCi_Single_Settings_Units_Spatial_setUnitA(_iSingleDocId, spUnit);
    return ok;
}

void Single_Header::setPixelSize(double sizeX, double sizeY) {
    RayCi_Single_Settings_Units_Spatial_setPixelSize(_iSingleDocId, sizeX, sizeY);
}

bool Single_Header::isPowerManually() {
    bool bManually = false;
    RayCi_Single_Settings_Units_Power_isManually(_iSingleDocId, &bManually);
    return bManually;
}

double Single_Header::getPower() {
    double dPower = 0;
    RayCi_Single_Settings_Units_Power_getPower(_iSingleDocId, &dPower);
    return dPower;
}

QString Single_Header::getPowerUnit() {
    char szPowerUnit_buffer[10];
    int nSize = _countof(szPowerUnit_buffer);
    RayCi_Single_Header_Camera_Settings_getA(_iSingleDocId, szPowerUnit_buffer, &nSize);
    return {szPowerUnit_buffer};
}

void Single_Header::setDivergenceActive(const bool bDivergenceActive) const {
    RayCi_Single_Settings_Units_Divergence_setActive(_iSingleDocId, bDivergenceActive);
}


